package com.manish.tabdemo;
import java.util.List;

import com.manish.tabdemo.R;
import com.manish.tabdemo.R.id;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class RistorantiListAdapter extends ArrayAdapter<RistorantiList> {
	private int				resource;
	private LayoutInflater	inflater;
	private Context 		context;
	public RistorantiListAdapter ( Context ctx, int resourceId, List<RistorantiList> objects) {
		super( ctx, resourceId, objects );
		resource = resourceId;
		inflater = LayoutInflater.from( ctx );
		context=ctx;
	}
	@Override
	public View getView ( int position, View convertView, ViewGroup parent ) { 
		convertView = ( RelativeLayout ) inflater.inflate( resource, null ); 
		RistorantiList Ristorante = getItem( position );
		TextView RistoranteName = (TextView) convertView.findViewById(R.id.RistoranteName);
		RistoranteName.setText(Ristorante.getName());
		 
		TextView address = (TextView) convertView.findViewById(R.id.Address);
		address.setText(Ristorante.getAddress());
		 
//		ImageView legendImage = (ImageView) convertView.findViewById(R.id.RistoranteImage);
//		String uri = "drawable/" + Ristorante.getImage();
//	    int imageResource = context.getResources().getIdentifier(uri, null, context.getPackageName());
//	    Drawable image = context.getResources().getDrawable(imageResource);
//	    legendImage.setImageDrawable(image);
	    
	    ImageView NationImage = (ImageView) convertView.findViewById(R.id.GoButton);
	    String uri = "drawable/" + Ristorante.getGo();
	    int imageResource = context.getResources().getIdentifier(uri, null, context.getPackageName());
	    Drawable image = context.getResources().getDrawable(imageResource);
	    NationImage.setImageDrawable(image);

		return convertView;
	}
}

